home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1984 June / 1984-06.d64 / begin corner_64 (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  4KB  |  162 lines

  1. 100 rem tic-tac-toe
  2. 110 goto 560
  3. 120 rem x
  4. 130 poke m,a:poke m+4,a:poke m+41,a
  5. 140 poke m+43,a:poke m+82,a:poke m+121,a
  6. 150 poke m+123,a:poke m+160,a:poke m+164,a
  7. 160 return
  8. 170 rem o
  9. 180 poke m,233:poke m+4,223:poke m+160,95:poke m+164,105
  10. 190 for i=1 to 3
  11. 200 poke m+i,a:poke m+i+160,a
  12. 210 poke m+40*i,a:poke m+40*i+4,a
  13. 220 next i
  14. 230 poke m+82,32
  15. 240 return
  16. 250 for i=m+c to m+c+160 step 40
  17. 260 poke i,cc(n):poke i+1,cc(n):poke i+2,cc(n):poke i+3,cc(n):poke i+4,cc(n)
  18. 270 next i
  19. 280 return
  20. 290 rem tone
  21. 300 poke f1,42:poke f2,62
  22. 310 poke w,17
  23. 320 for d=1 to 60:next d:poke w,0
  24. 330 return
  25. 340 x=n:p(e)=x:m=s(e):on x gosub 130,130,180
  26. 350 gosub 250
  27. 360 for i=1 to 7 step 3
  28. 370 if p(i)<>p(i+1) then 400
  29. 380 if p(i)<>p(i+2) then 400
  30. 390 on p(i)+1 goto 400,1550,1550,1550
  31. 400 next i
  32. 410 for i=1 to 3
  33. 420 if p(i)<>p(i+3) then 450
  34. 430 if p(i)<>p(i+6) then 450
  35. 440 on p(i)+1 goto 450,1550,1550,1550
  36. 450 next i
  37. 460 if p(5)<>x then 490
  38. 470 if (p(1)=x) and (p(9)=x) then 1550
  39. 480 if (p(3)=x) and (p(7)=x) then 1550
  40. 490 for i=1 to 9
  41. 500 if p(i)=0 then 540
  42. 510 next i
  43. 520 print "tie game!"
  44. 530 goto 1590
  45. 540 n=abs(n-4)
  46. 550 return
  47. 560 print "[147]":poke 53281,1
  48. 570 w=54276:poke w,0
  49. 580 print tab(15)"tic-tac-toe"
  50. 590 for i=1 to 9:read s(i):next i
  51. 600 data 1114,1122,1130,1434,1442
  52. 610 data 1450,1754,1762,1770
  53. 620 print "choose one of the position numbers."
  54. 630 print "try to get three in a row."
  55. 640 poke 54296,15:f1=54273:f2=54272:c=f2
  56. 650 poke w+1,128:poke w+2,16
  57. 660 a=160:cc(1)=6:cc(3)=10
  58. 670 print "alternate turns with the computer."
  59. 680 print "[144]x gets first move."
  60. 690 y=3:z=1:ch=2
  61. 700 print "choose  [144]f1 for [144]x"
  62. 710 print tab(8)"[144]f3 for [144]o"
  63. 720 get e$:if e$<>"[133]" and e$<>"[134]" then 720
  64. 730 if e$="[133]"then y=1:z=3
  65. 740 poke 198,0
  66. 750 print "choose  [144]f1 beginner"
  67. 760 print tab(8)"[144]f3 intermediate"
  68. 770 get e$:if e$<>"[133]" and e$<>"[134]" then 770
  69. 780 if e$="[133]" then ch=1
  70. 790 print "[147]":ct=int(14*rnd(0))+2
  71. 800 for i=1 to 9:p(i)=0:next i
  72. 810 for i=1080 to 1960 step 40
  73. 820 poke i,a:poke i+c,ct
  74. 830 poke i+8,a:poke i+8+c,ct
  75. 840 next i
  76. 850 for i=1353 to 1375
  77. 860 poke i,a:poke i+c,ct:poke i+320,a:poke i+320+c,ct
  78. 870 next i
  79. 880 for i=1 to 9:poke s(i)+82,i+48
  80. 890 poke s(i)+82+c,0:next i
  81. 900 n=1
  82. 910 if ch=2 then 1040
  83. 920 if y=1 then 970     
  84. 930 rem computer's move
  85. 940 e=int(9*rnd(0)+1):if p(e)<>0 then 940
  86. 950 gosub 340
  87. 960 rem your move
  88. 970 gosub 300
  89. 980 get e$:if e$=""then 980
  90. 990 if e$<"1" or e$>"9" then 980
  91. 1000 e=val(e$):if p(e)<>0 then 970
  92. 1010 gosub 340
  93. 1020 on ch goto 940,1060
  94. 1030 rem computer's move
  95. 1040 if y=1 then 970
  96. 1050 rem center position
  97. 1060 if p(5)=0 then e=5:goto 1520
  98. 1070 if p(5)=x then 1140
  99. 1080 rem diagonals
  100. 1090 if p(1)=0 and p(9)=z then e=1:goto 1520
  101. 1100 if p(1)=z and p(9)=0 then e=9:goto 1520
  102. 1110 if p(3)=0 and p(7)=z then e=3:goto 1520
  103. 1120 if p(3)=z and p(7)=0 then e=7:goto 1520
  104. 1130 rem columns
  105. 1140 for k=1 to 3
  106. 1150 if p(k)=x or p(k+3)=x or p(k+6)=x then 1200
  107. 1160 if p(k)+p(k+3)+p(k+6)<>2*z then 1200
  108. 1170 if p(k)=0 then e=k:goto 1520
  109. 1180 if p(k+3)=0 then e=k+3:goto 1520
  110. 1190 e=k+6:goto 1520
  111. 1200 next k
  112. 1210 rem rows
  113. 1220 for k=1 to 7 step 3
  114. 1230 if p(k)=x or p(k+1)=x or p(k+2)=x then 1280
  115. 1240 if p(k)+p(k+1)+p(k+2)<>2*z then 1280
  116. 1250 if p(k)=0 then e=k:goto 1520
  117. 1260 if p(k+1)=0 then e=k+1:goto 1520
  118. 1270 e=k+2:goto 1520
  119. 1280 next k
  120. 1290 rem prevent column
  121. 1300 for k=1 to 3
  122. 1310 if p(k)=z or p(k+3)=z or p(k+6)=z then 1360
  123. 1320 if p(k)+p(k+3)+p(k+6)<>2*x then 1360
  124. 1330 if p(k)=0 then e=k:goto 1520
  125. 1340 if p(k+3)=0 then e=k+3:goto 1520
  126. 1350 e=k+6:goto 1520
  127. 1360 next k
  128. 1370 rem prevent row
  129. 1380 for k=1 to 7 step 3
  130. 1390 if p(k)=z or p(k+1)=z or p(k+2)=z then 1440
  131. 1400 if p(k)+p(k+1)+p(k+2)<>2*x then 1440
  132. 1410 if p(k)=0 then e=k:goto 1520
  133. 1420 if p(k+1)=0 then e=k+1:goto 1520
  134. 1430 e=k+2:goto 1520
  135. 1440 next k
  136. 1450 if p(5)=z then 1500
  137. 1460 if p(1)=0 and p(9)=x then e=1:goto 1520
  138. 1470 if p(1)=x and p(9)=0 then e=9:goto 1520
  139. 1480 if p(3)=0 and p(7)=x then e=3:goto 1520
  140. 1490 if p(3)=x and p(7)=0 then e=7:goto 1520
  141. 1500 goto 940
  142. 1510 rem
  143. 1520 gosub 340
  144. 1530 goto 970
  145. 1540 rem game over
  146. 1550 if x<>y then 1580
  147. 1560 print "you win!!!"
  148. 1570 goto 1590
  149. 1580 print "computer wins!!"
  150. 1590 for i=1 to 20
  151. 1600 poke f1,int(60*rnd(0)+30)
  152. 1610 poke f2,int(200*rnd(0)+10)
  153. 1620 gosub 310
  154. 1630 next i
  155. 1640 print "try again? (y/n)";
  156. 1650 get e$:if e$="n" then 1690
  157. 1660 if e$<>"y" then 1650
  158. 1670 clr
  159. 1680 goto 560
  160. 1690 print "[147]"
  161. 1700 end
  162.